package com.hxunicorn.btc.core.customer.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.hxunicorn.btc.common.biz.BizPlatformInfo;
import com.hxunicorn.btc.common.biz.BizRptLog;
import com.hxunicorn.btc.common.utils.RptUtil;
import com.hxunicorn.btc.core.customer.mapper.BizPlatformInfoMapper;
import com.hxunicorn.btc.core.customer.mapper.BizRptLogMapper;
import com.hxunicorn.btc.core.customer.service.IBizRptService;
import com.hxunicorn.common.exception.HxException;
import com.hxunicorn.common.utils.SnowFlakeGenerator;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 墨塵
 * @since 2025/3/6
 */
@Service
public class BizRptServiceImpl implements IBizRptService {

    @Resource
    private BizPlatformInfoMapper bizPlatformInfoMapper;

    @Resource
    private BizRptLogMapper bizRptLogMapper;

    @Override
    public void rptDate() {
        List<BizPlatformInfo> infoList = bizPlatformInfoMapper.getList();
        if(CollectionUtils.isEmpty(infoList)){
           throw new HxException("表biz_platform_info缺失基础信息");
        }
        JSONObject param = new JSONObject();
        for(BizPlatformInfo item : infoList){
            if(item.getName().equals("platform_honors") || item.getName().equals("specialization_features")){
                param.put(item.getName(),item.getValue());
            }else{
                param.put(item.getName(),Double.valueOf(item.getValue()));
            }
        }
        JSONObject response = RptUtil.rptData(param);
        //记录数据
        BizRptLog log = new BizRptLog();
        log.setRptReq(param.toJSONString());
        log.setRptResp(response.toJSONString());
        log.setRptTime(DateUtil.now());
        bizRptLogMapper.insert(log);
    }
}
